//
//  CLMainViewController.swift
//  SinaCaoliang
//
//  Created by 曹亮 on 16/10/22.
//  Copyright © 2016年 曹亮. All rights reserved.
//

import UIKit

class CLMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //实例化tabbar

        let tabbar = CLTabBar()
        setValue(tabbar, forKey: "tabBar")

        addChildController(vc: CLHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildController(vc: CLMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildController(vc: CLDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildController(vc: CLMineViewController(), title: "我的", imageName: "tabbar_profile")

        print(view.subviews)
    }

    func addChildController(vc:UIViewController, title:String, imageName:String) -> Void {

        //设置标题
        vc.title = title
        //设置标题颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: UIControlState.selected)
        //设置按钮图片
        vc.tabBarItem.image = UIImage(named: imageName)
        //设置按钮选中图片并设置图片渲染模式
vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)

        let nav = CLNavigationViewController(rootViewController: vc)
        
        self.addChildViewController(nav)

    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
